This is the setup of the document.
# define and show parameters
actor<-params$actor
actor
## [1] "Keanu Reeves"
st<-params$stereotype
st
## [1] "wom_warm"
This imports data.
# create an object dataframe example `dfex` and assign to it the .sav file `sample.sav` that was introduced previously
dfex<-haven::read_sav("data/sample.sav")
# create an object movies metadata `dfmv` and assign to it the .xlsx file `movies.xlsx`
# note the different paths to these files
# note that we specify which sheet to read too; here only sheet 1 is imported
dfmv<-readxl::read_excel("mat/movies.xlsx",1)
# next, we check if the source material was imported successfully by observing the first lines in the tables
head(dfex)
## # A tibble: 6 × 9
## ppn gen age res res_other men_warm men_comp wom_warm wom_comp
## <dbl> <dbl+lbl> <dbl> <dbl+lbl> <chr> <dbl+lb> <dbl+lb> <dbl+lb> <dbl+lb>
## 1 459 1 [Female] 24 5 [Iasi] -99 3 [Und… 4 [Agr… 3 [Unde… 4 [Agre…
## 2 592 2 [Male] 21 5 [Iasi] -99 3 [Und… 4 [Agr… 3 [Unde… 3 [Unde…
## 3 634 2 [Male] 21 NA petrosani 4 [Agr… 5 [Str… 4 [Agre… 4 [Agre…
## 4 369 1 [Female] 30 8 [Gala… -99 NA NA 4 [Agre… 4 [Agre…
## 5 121 1 [Female] 21 4 [Timi… -99 4 [Agr… 3 [Und… 3 [Unde… 4 [Agre…
## 6 127 1 [Female] 20 4 [Timi… -99 4 [Agr… 4 [Agr… 4 [Agre… 2 [Disa…
head(dfmv)
## # A tibble: 4 × 6
## Movie Actor Like Why Grade Wikilink
## <chr> <chr> <chr> <chr> <dbl> <chr>
## 1 John Wick Keanu Reeves Yes Fight … 10 https:/…
## 2 Call me by your name Timothee Chalamet Yes Beauti… 10 https:/…
## 3 Terminator Arnold Schwarzenegger Yes Arnold 9 https:/…
## 4 4 months 3 weeks and 2 days <NA> Yes Portra… 8 https:/…
This is an example of how automatization can be implemented in the work flow. My list of movies include 4 entries. The title of those movies are John Wick, Call me by your name, Terminator, 4 months 3 weeks and 2 days. Is there a movie that I actually don’t like on that list, well, the answer is that I dislike exactly 0 movies on that list.
# 1 - imports dataset into object tempdf
tempdf<-haven::read_sav("data/tmpdf1.sav") %>%
sjlabelled::remove_all_labels() %>%
pivot_longer(contains("warm") | contains("comp")) %>%
filter(name %in% st)
# 2 - applies the ggplot to the dataset
ggplot(tempdf, aes(x=factor(gen), y=value)) +
labs(title=paste0("Evaluation based on ",st),
x="Gender",
y="Stereotype") +
geom_boxplot() +
theme_light()
Stereotipical evaluation
like | name | movie | wiki |
---|---|---|---|
Yes | Keanu Reeves | John Wick | https://en.wikipedia.org/wiki/John_Wick_(film) |
One other way to work with parameterized reports is to code the document such that it creates tables (or anything else for that matter) using a specific dataset. Basically, if the dataset format is identical but contains different N sizes or was collected by different teams or at different times, then parameterized reports can facilitate the creation of repeated reports at a button’s click.
# we assign the parameter sampledf to an object sampledf containing the dataset itself
sampledf<-paste0("data/",params$sampledf)
sampledf
## [1] "data/sample.sav"
abc<-haven::read_sav(sampledf)
head(abc)
## # A tibble: 6 × 9
## ppn gen age res res_other men_warm men_comp wom_warm wom_comp
## <dbl> <dbl+lbl> <dbl> <dbl+lbl> <chr> <dbl+lb> <dbl+lb> <dbl+lb> <dbl+lb>
## 1 459 1 [Female] 24 5 [Iasi] -99 3 [Und… 4 [Agr… 3 [Unde… 4 [Agre…
## 2 592 2 [Male] 21 5 [Iasi] -99 3 [Und… 4 [Agr… 3 [Unde… 3 [Unde…
## 3 634 2 [Male] 21 NA petrosani 4 [Agr… 5 [Str… 4 [Agre… 4 [Agre…
## 4 369 1 [Female] 30 8 [Gala… -99 NA NA 4 [Agre… 4 [Agre…
## 5 121 1 [Female] 21 4 [Timi… -99 4 [Agr… 3 [Und… 3 [Unde… 4 [Agre…
## 6 127 1 [Female] 20 4 [Timi… -99 4 [Agr… 4 [Agr… 4 [Agre… 2 [Disa…
nrow(abc)
## [1] 100
# assign parameterized data to an object dataframe
abc %>%
sjlabelled::remove_all_labels() %>%
pivot_longer(contains("warm") | contains("comp")) %>%
group_by(name) %>%
summarise(mean=mean(value, na.rm = TRUE), # we use missing remove TRUE (na.rm=TRUE) to make sure r gives an output
sd=sd(value, na.rm = TRUE),
min=min(value, na.rm = TRUE),
max=max(value, na.rm = TRUE))
## # A tibble: 4 × 5
## name mean sd min max
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 men_comp 3.91 0.755 2 5
## 2 men_warm 3.55 0.893 1 5
## 3 wom_comp 3.72 0.961 1 5
## 4 wom_warm 3.80 0.873 1 5